<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    li{
      width: 500px;
      height: 40px;
      background-color: #ac8787;
      margin-top: 10px;
    }
  </style>
</head>
<body>
  <div id="app">
    <button @click="changeLen">改变数组的length</button>
    <ul>
      <li @click="changeLi(index)" v-for="(item, index) in arr" :key="index">
        {{item}}
      </li>
    </ul>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue@2.7.14/dist/vue.js"></script>
  <script>
      const vm = new Vue({
        data: {
          arr: [1,2,3,4]
        },
        methods: {
          changeLi(index) {
            // this.arr[index] = '值改变了';
            this.$set(this.arr, index, '值改变了')
            console.log(this.arr);
          },
          changeLen(){
            this.arr.length = 0;
            console.log(this.arr);
          }
        },
      })

      vm.$mount('#app')
  </script>
</body>
</html>